﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Reflection;
using SoundEdge.Common;
using SoundEdge.WinControls;
using SoundEdge.Media.Filter;

namespace SoundEdge.Dashboard
{
    public partial class frmParserLibrary : DockContent
    {
        public frmParserLibrary()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SearchFilters();
        }

        private void SearchFilters()
        {
            Assembly assembly = Assembly.LoadFrom("SoundEdge.Filters.dll");
            if (assembly == null)
            {
                return;
            }
            foreach (Type pluginType in assembly.GetTypes())
            {
                if (!pluginType.IsPublic || pluginType.IsAbstract)
                {
                    continue;
                }
                Type typeInterface = pluginType.GetInterface("SoundEdge.Common.IWaveFilter", true);
                if (typeInterface != null)
                {
                    IWaveFilter filter = Activator.CreateInstance(assembly.GetType(pluginType.ToString())) as IWaveFilter;
                    (filter as WaveFilter).lblTitle.Text = filter.Title;
                    waveLibrary.Items.Add(new ListViewItem(filter.Title) { Tag = filter });
                }
                typeInterface = null;
            }
        }

        private void waveLibrary_ItemDrag(object sender, ItemDragEventArgs e)
        {
            DoDragDrop(e.Item, DragDropEffects.Move);
        }
    }
}
